﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ClarizenGadget.Models;
using Logic.ClarizenSvc;
using Logic;

namespace ClarizenGadget.Controllers
{
    public class ConduitController : Controller
    {
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ToolBar()
        {
            var msg = new GetMultipleTodayInfoMessage { InfoItems = new TodayInfoItem[] { TodayInfoItem.NewTasks, TodayInfoItem.OverdueManagedTask, TodayInfoItem.MyIssues } };
            var res = new QueryComponent().Execute(msg);
            var values = ((Logic.ClarizenSvc.GetMultipleTodayInfoResult)(res[0])).Results;
            ConduitToolbar model = new ConduitToolbar { NewIssues = (int)values[2].Value, NewTasks = (int)values[0].Value, OverdueTasks = (int)values[1].Value };
            return Json(model);
        }

        public ActionResult CreateGadget()
        {
            return View();
        }

        public ActionResult App()
        {
            return View();
        }

        public ActionResult ChromeLandingPage()
        {
            if (Request["https"] != "1")
                return Redirect("https" + Request.Url.ToString().Substring(4) + "&https=1");
            else
            {
                if (Request["url"].StartsWith(Logic.Constants.CurrentUrl, StringComparison.OrdinalIgnoreCase))
                    return View();
                else return Redirect("/tasks");
            }
        }
    }
}
